﻿@page "/songs/{SongId:int}/{SongName}"
@using MusicX.Web.Shared.Songs

<ErrorsList Errors="response?.Errors" />

@if (this.response == null)
{
    <p><em>Loading...</em></p>
}
else if (this.song == null)
{
    <p><em>Song not found.</em></p>
}
else
{
    <h1>@this.song.Artists - @this.song.SongTitle</h1>
    <SongCard Song="@this.song"></SongCard>
    <div>
        <!-- TODO: <button class="btn btn-primary" @onclick="AddSimilarSongs">Add similar songs</button> -->
    </div>
    <pre>@this.song.Lyrics</pre>
}

@code {
    [Parameter]
    public int SongId { get; set; }

    [Parameter]
    public string SongName { get; set; }

    ApiResponse<GetSongByIdResponse> response;

    GetSongByIdResponse song;

    protected override async Task OnInitializedAsync()
    {
        this.response = await this.ApiClient.GetSongById(this.SongId);
        this.song = this.response?.Data;
    }

    async Task AddSimilarSongs()
    {
        await this.ApiClient.AddSimilarSongs(new AddSimilarSongsRequest() { SongId = this.SongId });
    }
}
